package com.sinog.biz.service.business.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinog.biz.config.param.Converse;
import com.sinog.biz.mapper.havexml.OptFzlxMapper;
import com.sinog.biz.mapper.havexml.PrisaveTempMapper;
import com.sinog.biz.mapper.havexml.PrisonerFxExcelTempMapper;
import com.sinog.biz.mapper.havexml.PrisonerFxMapper;
import com.sinog.biz.mapper.havexml.PrisonerMainExcelTempMapper;
import com.sinog.biz.mapper.havexml.PrisonerMainMapper;
import com.sinog.biz.mapper.havexml.PrisonerSrExcelTempMapper;
import com.sinog.biz.mapper.havexml.PrisonerZnExcelTempMapper;
import com.sinog.biz.mapper.havexml.SystemCodeMapper;
import com.sinog.biz.service.business.SentenceService;
import com.sinog.biz.util.IdGen;
import com.sinog.core.domain.PrisaveTemp;
import com.sinog.core.domain.PrisonerFx;
import com.sinog.core.domain.PrisonerFxExcelTemp;
import com.sinog.core.domain.PrisonerMain;
import com.sinog.core.domain.SystemCode;
import com.sinog.core.model.UserDTO;
import com.sinog.core.util.JsonUtil;
import com.sinog.core.util.PageReturnUtil;
import com.sinog.core.util.StrUtil;
import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.Result;
import com.sinog.core.utilbean.ReturnCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @desc 服刑信息实现类
 * @author -
 * @date 2020-02-05-16:27
 */
@Slf4j
@Service
public class SentenceServiceImpl extends ServiceImpl<PrisonerFxMapper,PrisonerFx> implements SentenceService {

    @Resource
    private SystemCodeMapper systemCodeMapper;
    @Resource
    private PrisaveTempMapper prisaveTempMapper;
    @Resource
    private PrisonerMainMapper prisonerMainMapper;
    @Resource
    private PrisonerMainExcelTempMapper prisonerMainExcelTempMapper;
    @Resource
    private PrisonerFxMapper prisonerFxMapper;
    @Resource
    private PrisonerFxExcelTempMapper prisonerFxExcelTempMapper;
    @Resource
    private PrisonerSrExcelTempMapper prisonerSrExcelTempMapper;
    @Resource
    private PrisonerZnExcelTempMapper prisonerZnExcelTempMapper;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private OptFzlxMapper optFzlxMapper;

    /**
     * 描述
     * @param codeType codeType
     * @param pCodeId pCodeId
     * @return List<Map < String,Object>>
     */
    @Override
    public List<Map<String,Object>> getCodeName(String codeType,String pCodeId) {
        Map<String,Object> cloumMap = new HashMap<>(16);
        cloumMap.put("code_type",codeType);
        cloumMap.put("pcode_id",pCodeId);
        List<SystemCode> systemCodes = systemCodeMapper.selectByMap(cloumMap);
        List<Map<String,Object>> list = new ArrayList<>(16);
        for(SystemCode sc : systemCodes) {
            Map<String,Object> map = new HashMap<>(16);
            map.put("codeId",sc.getCodeId());
            map.put("codeName",sc.getCodeName());
            list.add(map);
        }
        return list;
    }

    /**
     * 根据罪名和犯罪类型的id去查询出对应的名称
     * @param codeIds codeIds
     * @return Result
     */
    @Override
    public Result getCodeName(String codeIds) {
        String[] cIds = codeIds.split(",");
        List<String> list = Arrays.asList(cIds);
        Set<String> ids = new HashSet<>(16);
        ids.addAll(list);
        for(String id : ids) {
            try {
                Cursor<ZSetOperations.TypedTuple<String>> zuiming = redisTemplate.opsForZSet()
                                                                                 .scan("zuiming",ScanOptions.scanOptions()
                                                                                                            .match(id + "|*")
                                                                                                            .count(1000)
                                                                                                            .build());
                while(zuiming.hasNext()) {
                    ZSetOperations.TypedTuple<String> next = zuiming.next();
                    String value = next.getValue();
                    assert value != null;
                    redisTemplate.opsForZSet().incrementScore("zuiming",value,1);
                }
                zuiming.close();
            } catch(Exception e) {
                throw new RuntimeException(e);
            }
        }
        QueryWrapper<SystemCode> wrapper = new QueryWrapper<>();
        wrapper.eq("code_type",Constants.CodeType.CODE_ZMFL_DM).in("code_id",ids);
        List<SystemCode> codeList = systemCodeMapper.selectList(wrapper);
        if(!CollectionUtils.isEmpty(codeList)) {
            List<HashMap<String,String>> collect = codeList.stream().map((code) -> {
                HashMap<String,String> map = new HashMap<>(16);
                map.put("codeId",code.getCodeId());
                map.put("codeName",code.getCodeName());
                return map;
            }).collect(Collectors.toList());
            HashMap<String,String> fzlxMap = new HashMap<>(16);
            Set<String> temp = new HashSet<>();
            for(SystemCode code : codeList) {
                String codeId = optFzlxMapper.getFzlxById(code.getCodeId());
                temp.add(systemCodeMapper.selectOne(new QueryWrapper<SystemCode>().eq("code_type",Constants.CodeType.CODE_ZMFL_DM)
                                                                                  .eq("code_id",codeId)).getCodeName());
            }
            Object[] arr = temp.toArray();
            String fzlxName = StringUtils.join(arr,",");
            fzlxMap.put("codeType",fzlxName);
            collect.add(fzlxMap);
            return Result.success(collect);
        }
        return null;
    }

    /**
     * 来判断这个服刑人员有没有刑期起止日，有返回yes,无返回no
     * @param priNum 罪犯编号
     * @return String
     */
    @Override
    public String selectHasDate(String priNum) {
        PrisonerFx prisonerFx = prisonerFxMapper.selectOne(new QueryWrapper<PrisonerFx>().eq("pri_num",priNum)
                                                                                         .last("limit 1"));
        Date priStop;
        Date priStopNow;
        if(null != prisonerFx) {
            priStop = prisonerFx.getPriStop();
            priStopNow = prisonerFx.getPriStopNow();
            if((null != priStop || null != priStopNow)) {
                return Constants.StrFinalValue.SAYYES;
            }
        }
        return Constants.StrFinalValue.SAYNO;
    }

    /**
     * 根据犯罪编号查询该罪犯基本信息和服刑信息必填项是不是全部填写完成
     * @param prinum 罪犯编号
     * @return Integer
     */
    @Override
    public Integer getIsAll(String prinum) {
        return prisonerMainMapper.getIsAll(prinum);
    }

    /**
     * 预安置人员信息录入 - 保存/更新 服刑信息
     * @param data data
     * @param user user
     * @return Result
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result saveSentenceInfo(String data,UserDTO user) {
        //1、解析参数
        PrisonerFx prisonerFx = JsonUtil.toBean(data,PrisonerFx.class);
        Date date1 = new Date();
        //2、根据前台传递的罪名查询犯罪类型
        //因为前段传过来的fzlx和罪名Id是一样的，没有进行筛选
        String oldFzlx = prisonerFx.getFzlx();
        //现在需要重新根据罪名，把犯罪类型查询出来
        prisonerFx.setFzlx(findFzlx(oldFzlx,new HashSet<>(16)));
        boolean flag;
        //3、根据罪犯编号查询服刑表，存在：更新；不存在：新增
        PrisonerFx p = prisonerFxMapper.selectOne(new QueryWrapper<PrisonerFx>().eq("pri_num",prisonerFx.getPriNum())
                                                                                .last("limit 1"));
        if(null == p) {
            prisonerFx.setAdduserid(user.getDepartid());
            prisonerFx.setCreateUser(user.getAccount());
            prisonerFx.setCreateTime(date1);
            prisonerFx.setUpdateUser(user.getAccount());
            prisonerFx.setUpdateTime(date1);
            String id = IdGen.strid();
            prisonerFx.setId(id);
        } else {
            prisonerFx.setId(p.getId());
            prisonerFx.setUpdateTime(date1);
            prisonerFx.setUpdateUser(user.getAccount());
            // 当刑期止日为空的时候，insertorUpdata方法不会进行更新，手动进行更新
            if(null == prisonerFx.getPriStop()) {
                prisonerFxMapper.updatePriStop(p.getPriNum());
            }
        }
        //4、服刑表入库
        flag = prisonerFx.insertOrUpdate();
        //5、状态表入库
        PrisaveTemp pt = new PrisaveTemp();
        PrisaveTemp prisaveTemp = prisaveTempMapper.selectById(prisonerFx.getPriNum());
        if(null == prisaveTemp) {
            prisaveTemp = new PrisaveTemp();
            prisaveTemp.setCreateUser(user.getAccount());
            prisaveTemp.setCreateTime(date1);
            prisaveTemp.setUpdateUser(user.getAccount());
            prisaveTemp.setUpdateTime(date1);
            String id = IdGen.strid();
            pt.setId(id);
            pt.setPriNum(prisonerFx.getPriNum());
            pt.setFxFlag(Constants.Number.NUM_ONE);
            flag = flag && pt.insertOrUpdate();
        } else {
            prisaveTemp.setUpdateUser(user.getAccount());
            prisaveTemp.setUpdateTime(date1);
            prisaveTemp.setFxFlag(Constants.Number.NUM_ONE);
            prisaveTemp.insertOrUpdate();
        }
        //6、当前用户level
        String level = user.getLevel();
        //7、查询主表并更新主表state
        PrisonerMain pm = prisonerMainMapper.selectPrisonerMain(prisonerFx.getPriNum());
        pm.setUpdateUser(user.getAccount());
        pm.setUpdateTime(date1);
        //8、更新状态表另外三个状态为1，更新主表state=3（司法局、司法所核查成功）
        if(flag) {
            String state = Constants.NumberStr.NUM_STR_ONE;
            //修改需求，用户的基本信息已经录入，当用户录入罪犯的服刑信息，会将中间表的三个flag全修改为1
            int i = prisaveTempMapper.updateThreeFlag(Constants.Number.NUM_ONE,pm.getPriNum(),user.getAccount(),date1);
            if(0 < i) {
                //区县司法局和司法所操作执行核查- state置为3核查成功
                if(Constants.OrgLevel.LEVEL_QXSFJ.equals(level) || Constants.OrgLevel.LEVEL_SFS.equals(level)) {
                    prisonerMainMapper.updateStateByPrinum(pm.getPriNum(),Constants.NumberStr.NUM_STR_THREE);
                } else {
                    //将罪犯的state改为1待核查
                    prisonerMainMapper.updateStateByPrinum(pm.getPriNum(),state);
                }
            }
            return Result.success("保存成功");
        }
        return Result.failure(ReturnCode.SAVE_FAILED);
    }

    /**
     * 预安置人员信息录入 - 保存/更新 服刑信息excel
     * @param data data
     * @param user user
     * @return Result
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result saveSentenceInfoExcel(String data,UserDTO user) {
        //1、解析参数
        PrisonerFxExcelTemp prisonerFx = JsonUtil.toBean(data,PrisonerFxExcelTemp.class);
        prisonerFx.setCheckFlag(Constants.NumberStr.NUM_STR_ZERO);
        prisonerFx.setId(IdGen.strid());
        //mainCount>0说明数据未填写完整
        //mainCount=0说明数据已经完整
        //当下面四个值都为0就设置主表的success_flag=0；
        int mainCount = prisonerMainExcelTempMapper.selectMainByCheckFlag(prisonerFx.getPriNum());
        int srCount = prisonerSrExcelTempMapper.selectSrByCheckFlag(prisonerFx.getPriNum());
        int znCount = prisonerZnExcelTempMapper.selectZnByCheckFlag(prisonerFx.getPriNum());
        if(mainCount + srCount + znCount == Constants.Number.NUM_ZERO) {
            prisonerMainExcelTempMapper.updateMainSuccessFlag(prisonerFx.getPriNum());
        }
        boolean b = prisonerFx.insertOrUpdate();
        if(b) {
            return Result.success("保存成功");
        }
        return Result.failure(ReturnCode.SAVE_FAILED);
    }

    /**
     * 预安置人员信息录入 - 服刑信息页面 - 罪名下拉列表
     * @param codeType codeType
     * @param codeId codeId
     * @param queryKey queryKey
     * @param pageIndex pageIndex
     * @param pageSize pageSize
     * @return String
     */
    @Override
    public String getZuiMingList(
            @Converse(caseIf = "-1", converseTo = "0") String codeType,
            @Converse(caseIf = "-1", converseTo = "0") String codeId,
            @Converse(caseIf = "-1", converseTo = "0") String queryKey,Integer pageIndex,Integer pageSize) {
        if(Constants.CodeType.CODE_ZMFL_DM.equals(codeType)) {
            //分页查询起始位置
            long start = Long.parseLong(String.valueOf(pageIndex * pageSize));
            //分页查询结束位置
            long end = Long.parseLong(String.valueOf((pageSize - 1) + start));
            //查询罪名集合
            List<HashMap<String,String>> zuimingList = new ArrayList<>();
            //如果redis中没有罪名，则从数据库中查询，放入redis中，之后从redis中获取罪名
            //获取redis中罪名数量
            long count = redisTemplate.opsForZSet().zCard("zuiming");
            if(count == 0) {
                //先获取所有罪名
                List<Map<String,String>> allZuiMingList = systemCodeMapper.getAllZuiMingList();
                //然后将罪名编号和名称拼再一起放入redis的zset中
                for(Map<String,String> map : allZuiMingList) {
                    StringBuilder sb = new StringBuilder();
                    sb.append(map.get("codeId"));
                    sb.append("|");
                    sb.append(map.get("codeName"));
                    redisTemplate.opsForZSet().add("zuiming",sb.toString(),1);
                }
            }
            if("".equals(queryKey) || null == queryKey) {
                //如果没有查询条件，按分数排名
                //获取分页查询数据
                Set<String> zuiming = redisTemplate.opsForZSet().reverseRange("zuiming",start,end);
                assert zuiming != null;
                for(String zuimingAndScore : zuiming) {
                    String[] split = zuimingAndScore.split("\\|");
                    HashMap<String,String> zuimingMap = new HashMap<>(16);
                    zuimingMap.put("codeId",split[0]);
                    zuimingMap.put("codeName",split[1]);
                    zuimingList.add(zuimingMap);
                }
            } else {
                //如果有查询条件，按分数排名
                try {
                    Cursor<ZSetOperations.TypedTuple<String>> zuiming = redisTemplate.opsForZSet()
                                                                                     .scan("zuiming",ScanOptions.scanOptions()
                                                                                                                .match("*" + queryKey + "*")
                                                                                                                .count(1000)
                                                                                                                .build());
                    count = 0;
                    //分页标记
                    int n = pageIndex * pageSize;
                    //分页查询数量
                    int m = (pageIndex + 1) * pageSize;
                    while(zuiming.hasNext()) {
                        ZSetOperations.TypedTuple<String> next = zuiming.next();
                        String zuimingAndScore = next.getValue();
                        assert zuimingAndScore != null;
                        String[] split = zuimingAndScore.split("\\|");
                        HashMap<String,String> zuimingMap = new HashMap<>(16);
                        // 针对条件分页查询操作
                        // 如果当前条数未达到查询数量
                        if(count >= n && count < m) {
                            zuimingMap.put("codeId",split[0]);
                            zuimingMap.put("codeName",split[1]);
                            zuimingList.add(zuimingMap);
                        }
                        count++;
                    }
                    zuiming.close();
                } catch(Exception e) {
                    throw new RuntimeException(e);
                }
            }
            return JsonUtil.toText(count,zuimingList);
        } else {
            Page<Map<String,String>> page = new Page<>(pageIndex + 1,pageSize);
            page = page.setRecords(systemCodeMapper.getZuiMingList(page,codeType,codeId,queryKey));
            return PageReturnUtil.pageReturn(page);
        }
    }

    /**
     * 描述
     * @param tempMap tempMap
     * @return Set<String>
     */
    private Set<String> getCodeNameById(Map<String,String> tempMap) {
        if(null == tempMap.get(Constants.StrFinalValue.CODEID)) {
            return new HashSet<>(16);
        }
        String[] codeIdArr = tempMap.get("codeId").split(",");
        Set<String> codeName = new HashSet<>(16);
        List<Map<String, String>> codeNameList = systemCodeMapper.getCodeNameByCodeId(Arrays.asList(codeIdArr));
        if(!CollectionUtils.isEmpty(codeNameList)) {
            codeName = codeNameList.stream().map(item -> item.get("codeName")).collect(Collectors.toSet());
        }
        return codeName;
    }

    /**
     * 查询出顶层id,也就是对应的犯罪类型
     * @param ids ids
     * @param set set
     * @return String
     */
    private String findFzlx(String ids,HashSet<String> set) {
        String[] idArr = ids.split(",");
        for(String s : idArr) {
            String id = optFzlxMapper.findFzlxById(s);
            set.add(id);
        }
        return StringUtils.join(set,",");
    }

    /**
     * 获得罪犯的服刑信息
     * @param prinum prinum
     * @return String
     */
    @Override
    public String getSenInfoById(String prinum) {
        PrisonerFx prisonerFx = prisonerFxMapper.selectById(prinum);
        String pinggu = prisonerFxMapper.getPingGu(prinum);
        //通过罪犯编号获取罪犯主表信息---判断刑止日期不能大于入监日期 -- by pzc
        PrisonerMain prisonerMain = prisonerMainMapper.selectById(prinum);
        Map<String,Object> fxmap = new HashMap<>(16);
        if(null != prisonerFx) {
            String pristr = prisonerFx.getPriNum();
            //是否具有违法犯罪倾向
            String weifa = prisonerFx.getWeifa();
            //是否疾病、残疾
            String canji = prisonerFx.getCanji();
            //案犯类别
            String aftype = prisonerFx.getAftype();
            String idstr = prisonerFx.getId();
            //犯人的刑期止日
            Date priStop = prisonerFx.getPriStop();
            Date priStopNow = prisonerFx.getPriStopNow();
            String pritime = prisonerFx.getPritime();
            String fxText = JsonUtil.toText(prisonerFx);
            fxmap = JsonUtil.toMap(fxText);
            fxmap.put("id",idstr);
            fxmap.put("prinum",pristr);
            fxmap.put("pinggu",pinggu);
            //增加现邢期至日
            //将罪犯入监日期也返回，用于判断刑止日期不能小于入监日期
            //将罪犯出生日期也返回，用于判断刑起日期不能小于出生日期-- by pzc
            if(prisonerMain.getAddtime() != null) {
                fxmap.put("addtime",prisonerMain.getAddtime());
            } else {
                fxmap.put("addtime","");
            }
            if(prisonerMain.getAge() != null) {
                fxmap.put("age",prisonerMain.getAge());
            } else {
                fxmap.put("age","");
            }
            if(StrUtil.containsEquals(pritime,Constants.PritimeTypeNow.PRITIME_WUQI,Constants.PritimeTypeNow.PRITIME_SIHUAN,Constants.PritimeTypeNow.PRITIME_SIXING)) {
                fxmap.put("xianxingqizhiri","");
            } else {
                fxmap.put("xianxingqizhiri",null == priStopNow ? priStop : priStopNow);
            }
            fxmap.put("weifa",weifa);
            fxmap.put("canji",canji);
            fxmap.put("Aftype",aftype);
            Map<String,String> tempMap = new HashMap<>(16);
            tempMap.put("codeType",Constants.CodeType.CODE_ZMFL_DM);
            //回显的罪名
            tempMap.put("codeId",prisonerFx.getCritype());
            fxmap.put("critypename",getCodeNameById(tempMap));
            tempMap.put("codeId",prisonerFx.getFzlx());
            fxmap.put("fzlxname",getCodeNameById(tempMap));
            tempMap.put("codeType",Constants.CodeType.CODE_ZYFL_DM);
            tempMap.put("codeId",prisonerFx.getJinengtype());
            SystemCode codeByMap = systemCodeMapper.getCodeByMap(tempMap);
            fxmap.put("jinengtypeName",null == codeByMap ? null : codeByMap.getCodeName());
            tempMap.put("codeType",Constants.CodeType.CODE_QX_2019);
            tempMap.put("codeId",prisonerFx.getPritime());
            SystemCode codeByMap1 = systemCodeMapper.getCodeByMap(tempMap);
            fxmap.put("pritimeName",null == codeByMap1 ? null : codeByMap1.getCodeName());
            tempMap.put("codeType",Constants.CodeType.CODE_FJX);
            tempMap.put("codeId",prisonerFx.getAddpenalty());
            //获取服刑信息的附加刑信息
            String[] addpenalties = prisonerFx.getAddpenalty().split(",");
            fxmap.put("addpenaltyName",systemCodeMapper.getAddpenaltyName(Arrays.asList(addpenalties)));
            tempMap.put("codeType",Constants.CodeType.CODE_AFLB);
            tempMap.put("codeId",prisonerFx.getAftype());
            SystemCode codeByMap2 = systemCodeMapper.getCodeByMap(tempMap);
            fxmap.put("aftypeName",null == codeByMap2 ? null : codeByMap2.getCodeName());
            tempMap.put("codeType",Constants.CodeType.CODE_ZY_DM);
            tempMap.put("codeId",prisonerFx.getBqzy());
            SystemCode codeByMap3 = systemCodeMapper.getCodeByMap(tempMap);
            fxmap.put("bqzyName",null == codeByMap3 ? null : codeByMap3.getCodeName());
            fxmap.put("result",Constants.NumberStr.NUM_STR_ONE);
        } else {
            //将罪犯入监日期也返回，用于判断刑止日期不能小于于入监日期
            //将罪犯出生日期也返回，用于判断刑起日期不能小于出生日期-- by pzc
            if(prisonerMain.getAddtime() != null) {
                fxmap.put("addtime",prisonerMain.getAddtime());
            } else {
                fxmap.put("addtime","");
            }
            if(prisonerMain.getAge() != null) {
                fxmap.put("age",prisonerMain.getAge());
            } else {
                fxmap.put("age","");
            }
            // -1代表没有录入过服刑信息
            fxmap.put("result",Constants.NumberStr.NUM_STR_FU_ONE);
        }
        return JsonUtil.toText(fxmap);
    }

    /**
     * 获得罪犯的服刑信息excel
     * @param prinum prinum
     * @return String
     */
    @Override
    public String getSenInfoByIdExcel(String prinum) {
        PrisonerFxExcelTemp prisonerFx = prisonerFxExcelTempMapper.selectById(prinum);
        String pinggu = prisonerFxMapper.getPingGu(prinum);
        if(null != prisonerFx) {
            String pristr = prisonerFx.getPriNum();
            //是否疾病、残疾
            String canji = prisonerFx.getCanji();
            //案犯类别
            String aftype = prisonerFx.getAftype();
            String idstr = prisonerFx.getId();
            //犯人的刑期止日
            Date priStop = prisonerFx.getPriStop();
            String fxText = JsonUtil.toText(prisonerFx);
            Map<String,Object> fxmap = JsonUtil.toMap(fxText);
            fxmap.put("id",idstr);
            fxmap.put("prinum",pristr);
            fxmap.put("pinggu",pinggu);
            //增加现邢期至日
            fxmap.put("xianxingqizhiri",priStop);
            fxmap.put("canji",canji);
            fxmap.put("Aftype",aftype);
            Map<String,String> tempMap = new HashMap<>(16);
            tempMap.put("codeType",Constants.CodeType.CODE_ZMFL_DM);
            //回显的罪名
            tempMap.put("codeId",prisonerFx.getCritype());
            fxmap.put("critypename",getCodeNameById(tempMap));
            tempMap.put("codeId",prisonerFx.getFzlx());
            fxmap.put("fzlxname",getCodeNameById(tempMap));
            tempMap.put("codeType",Constants.CodeType.CODE_ZYFL_DM);
            tempMap.put("codeId",prisonerFx.getJinengtype());
            SystemCode codeByMap = systemCodeMapper.getCodeByMap(tempMap);
            fxmap.put("jinengtypeName",null == codeByMap ? null : codeByMap.getCodeName());
            tempMap.put("codeType",Constants.CodeType.CODE_QX_2019);
            tempMap.put("codeId",prisonerFx.getPritime());
            SystemCode codeByMap1 = systemCodeMapper.getCodeByMap(tempMap);
            fxmap.put("pritimeName",null == codeByMap1 ? null : codeByMap1.getCodeName());
            tempMap.put("codeType",Constants.CodeType.CODE_FJX);
            tempMap.put("codeId",prisonerFx.getAddpenalty());
            //获取服刑信息的附加刑信息
            //excel导入时不填写罪名会抛空指针异常
            if(null != prisonerFx.getAddpenalty()) {
                String[] addpenalties = prisonerFx.getAddpenalty().split(",");
                fxmap.put("addpenaltyName",systemCodeMapper.getAddpenaltyName(Arrays.asList(addpenalties)));
                List<String> addpenaltyName = systemCodeMapper.getAddpenaltyName(Arrays.asList(addpenalties));
                log.info(String.valueOf(addpenaltyName));
            }
            tempMap.put("codeType",Constants.CodeType.CODE_AFLB);
            tempMap.put("codeId",prisonerFx.getAftype());
            SystemCode codeByMap2 = systemCodeMapper.getCodeByMap(tempMap);
            fxmap.put("aftypeName",null == codeByMap2 ? null : codeByMap2.getCodeName());
            tempMap.put("codeType",Constants.CodeType.CODE_ZY_DM);
            tempMap.put("codeId",prisonerFx.getBqzy());
            SystemCode codeByMap3 = systemCodeMapper.getCodeByMap(tempMap);
            fxmap.put("bqzyName",null == codeByMap3 ? null : codeByMap3.getCodeName());
            return JsonUtil.toText(fxmap);
        }
        return Constants.NumberStr.NUM_STR_FU_ONE;
    }

    @Override
    public List<Map<String,String>> getAllZuiMingList(){
        //先获取所有罪名
        List<Map<String,String>> allZuiMingList = systemCodeMapper.getAllZuiMingList();
        //然后将罪名编号和名称拼再一起放入redis的zset中
        for(Map<String,String> map : allZuiMingList) {
            StringBuilder sb = new StringBuilder();
            sb.append(map.get("codeId"));
            sb.append("|");
            sb.append(map.get("codeName"));
            redisTemplate.opsForZSet().add("zuiming",sb.toString(),1);
        }
        return allZuiMingList;
    }

}